from openai import OpenAI
from dotenv import load_dotenv
import os

load_dotenv()

client = OpenAI(
	base_url="https://ai.gitee.com/v1",
	api_key=os.getenv("api_key"),
	default_headers={"X-Failover-Enabled":"true"},
)


response = client.chat.completions.create(
	messages=[
		{
			"role": "system",
			"content": "You are a helpful and harmless assistant. You should think step-by-step." # 可根据需要替换提示词
		},
		{
			"role": "user",
			"content": "Can you please let us know more details about your request?" # 替换成用户的具体问题
		}
	],
	model="DeepSeek-R1",
	stream=True,
	max_tokens=8192,
	temperature=0.6,
	top_p=0.7,
	extra_body={
		"top_k": 50,
	},
	frequency_penalty=0,
)

fullResponse = ""
print("Response:")
for chunk in response:
    if not chunk.choices:
        continue
    if not hasattr(chunk.choices[0], 'delta'):
        continue
    delta = chunk.choices[0].delta
    if delta is None:
        continue
    if hasattr(delta, 'reasoning_content') and delta.reasoning_content:
        fullResponse += delta.reasoning_content
        print(f"\033[90m{delta.reasoning_content}\033[0m", end="", flush=True)
    elif hasattr(delta, 'content') and delta.content:
        fullResponse += delta.content
        print(delta.content, end="", flush=True)